package com.longqinuo.mycarservice.utils;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.longqinuo.mycarservice.R;

import java.util.List;
import java.util.Map;

/**
 * Created by zxw on 2016/6/25.
 */
public class BreakResultAdapter extends BaseAdapter{
    private Context mContext;
    private List<Map<String,String>> mList;

    public BreakResultAdapter(Context context,List<Map<String,String>> list) {
        this.mContext = context;
        this.mList = list;
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.break_result_item,null);
            holder = new ViewHolder(convertView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.time.setText(mList.get(position).get("time"));
        holder.place.setText("违章地址："+mList.get(position).get("place"));
        holder.behavior.setText("违章行为："+mList.get(position).get("behavior"));
        holder.fine.setText("罚款："+mList.get(position).get("fine")+"元");
        holder.grade.setText("扣分："+mList.get(position).get("grade")+"分");
        return convertView;
    }

    public static class ViewHolder {
        public ViewHolder(View itemView) {
            this.time = (TextView) itemView.findViewById(R.id.tv_time_break_result);
            this.place = (TextView) itemView.findViewById(R.id.tv_place_bread_result);
            this.behavior = (TextView) itemView.findViewById(R.id.tv_behavior_break_result);
            this.fine = (TextView) itemView.findViewById(R.id.tv_fine_result);
            this.grade = (TextView) itemView.findViewById(R.id.tv_grade_number_result);
        }
        private TextView time;
        private TextView place;
        private TextView behavior;
        private TextView fine;
        private TextView grade;
    }
}
